from tkinter import *
import tkinter.messagebox
from mainpage import *
import zipfile, os



def plane_description(root2,s,name):
    # 创建应用程序窗口
    root3 = Toplevel()
        # 创建标题
    root3.title("飞机大战简介")
        # 设置窗口大小
    convas = tkinter.Canvas(root3, height=500, width=500, bg="#ADA758")
    root3.geometry('500x500+400+150')

        # 创建一个图片管理类
    photo = tkinter.PhotoImage(file="image/feiji.png")  # file：t图片路径
    imgLabel = tkinter.Label(root3, image=photo, compound=tkinter.CENTER, bg="#ADA758")  # 把图片整合到标签类中
    imgLabel.pack(side=tkinter.TOP)  # 自动对齐
    imgLabel.place(x=0, y=0,width=500, height=200)
    convas.pack()


    labelName = tkinter.Label(root3, text='飞机大战', width=80,bg="#ADA758", font=("微软雅黑", 14))
    labelName.place(x=170, y=250, width=100, height=40)

    def download_game(s,name):
        filename = "plane.zip"
        if tkinter.messagebox.askokcancel('飞机大战',"你确认下载飞机大战这个游戏吗?"):
            msg = 'l {} {}'.format(name,filename)
            s.send(msg.encode())
            print("开始下载")
        # 开始下载游戏
            try:
                with zipfile.ZipFile("/home/tarena/game/%s"%filename) as zfile:
                    zfile.extractall(path="/home/tarena/game")
                    print("下载成功")
                    print("启动游戏")
                    os.system("python3 /home/tarena/game/plane/plane.py")
            except zipfile.BadZipFile as e:
                tkinter.messagebox.showinfo(title='飞机大战', message='下载游戏失败，请检查！')
                print (zfile_path+" is a bad zip file ,please check!")
            tkinter.messagebox.showinfo(title='飞机大战', message='游戏已结束！')
        else:
            print("你未下载此游戏！")

    def play_game():
        download_game(s,name)

    labelName = tkinter.Label(root3, text='游戏简介:', width=80,bg="#ADA758", font=("微软雅黑", 14))
    labelName.place(x=20, y=270, width=100, height=40)
    labelName1 = tkinter.Label(root3,text='游戏启示: 现在已经学完了 Python 基本知识点所以想做一下\n\
        游戏规则:游戏里会出现一个打飞机和好多小飞机战斗，如果大飞机被打败， 游戏则结束！\n\
        游戏意义：压力大, 消遣一下生活的一些压力！',bg="#ADA758", width=200)
    labelName1.place(x=80, y=310, width=300, height=70)


    button3 = Button(root3, text='打开', bg="#ADA758",font=("微软雅黑", 14),command=play_game)
    button3.place(x=90, y=420, width=100, height=40)


    def exit():
        print("退出了游戏！")
        root3.destroy()

    button4 = Button(root3, text='退出', bg="#ADA758",font=("微软雅黑", 14), command=exit)
    button4.place(x=300, y=420, width=100, height=40)
        # 启动消息循环
    root3.mainloop()